package gpar;

import gpar.io.*;
import gpar.ep.*;

import java.util.Date;
import java.util.Random;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.tools.JavaCompiler;


/**
 * The main class of this program.  
* <p>
 * 
 * @author Maarten Inja
 */
public class Program
{
    //////////////////// variables in the p* static final field
    public static final String CONFIG_FILE = "config.txt";
    public static final String CONFIG_DELIMITER = "=";

    ////////////////////////// program variables (should read from config.txt)
    public static int defaultNumberOfFitnessRounds = 10;

    ////////////////////////// local variables
    private Compiler compiler;
    private RobocodeController robocodeController;
    private EvolutionaryProcess evolutionaryProcess;

    public static Random random;     

    public Program ()
    {
        print("Starting Program at " + dateTimeString() + ", in directory: ");
        println(System.getProperty("user.dir"));
        Settings.init();

        // create all the instances of the important required elements 
        println("Initializing standard components");
        compiler = new Compiler(this);
        robocodeController = new RobocodeController(this);
        evolutionaryProcess = new EvolutionaryProcess(this);

        // make the option read seed from file! 
        random = new Random();
    
        evolutionaryProcess.run();
    }


    /**
     * Prints an object to both the terminal and the log file. Please use this as textual output at any time
     * as previous projects have proven the effectiveness of doing this. 
     * <p>
     * <b>HOWEVER</b>, recently it seemed as if Java had this INBUILT!  Further investigation is needed to 
     * check if this is the case. We might still be better of using this as it could be extremely handy to 
     * have one central place every where output passes through, ready to be managed.
     * 
     * @param o	The object to print. This could be anything.
     * @see #println(Object o)
     */
    public static void print(Object o)
    {
        System.out.print(o.toString());
        //Io.writeFile(LOG_FILE, o.toString());
    }

    /**
     * Same as print but also adds a newline. 
     * 
     * @param o	The object to print. This could be anything. 
     * @see #print(Object o)
     */
    public static void println(Object o)
    {
        print(o + "\n");
    }


    private static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    public static String dateTimeString()
    {
        Date date = new Date();
        return dateFormat.format(date);
    }


    /** Main entry point of the program, tries to create an instance of Program and parses the command 
     * line arguments
     * <p>
     * @param args	Command line arguments to be parsed (currently nothing is done with this variable!
     */
    public static void main(String args[])
    {
	    new Program();
    }   


    // {{{ public properties


    public Compiler getCompiler()
    {
        return compiler;
    }

    public RobocodeController getRobocodeController()
    {
        return robocodeController;
    }
    
    // }}}


}























